/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DETECTOR_H__
#define __DETECTOR_H__

#include "EvolutiveLib.h"
#include "Classifier.h"

namespace Evolutive {

	//! Defines the type of region grouping method
	enum EVOLUTIVELIB_API REGJOIN_METHOD {REGJOIN_MEAN,REGJOIN_BOUNDINGBOX,REGJOIN_SMALLER};
	
	//! Class that codifies a detector class.
	class EVOLUTIVELIB_API CDetector
	{
		//! Methods
	public:
		//! Default constructor		
		CDetector(void);

		//! Default destructor
		virtual ~CDetector(void);

#ifdef USE_OPENCV
		//! Find the object regions in an image
		void FindRegions(CRectVector *Regions,IplImage *Image);		
		static void FindRegions(CRectVector *Regions,IplImage *Image,CClassifier *Classifier,double ScaleStep=1.2,double MinScale=1.0,double MaxScale=4.0);		

		//! Show the regions over the input image
		void ShowRegions(CRectVector *Regions,IplImage *Image,int WaitTime=0);

		//! Create a copy of the input image with the regions
		IplImage* CreateRegionsImage(CRectVector *Regions,IplImage *Image);

		//! Assigns the classifier to be used
		void SetClassifier(CClassifier *Classifier);

		//! Classify a given image
		double GetClass(IplImage *Image);
		static double GetClass(IplImage *Image,CClassifier *Classifier);

		//! Set the maximum scale
		void SetMaxScale(double Scale);

		//! Set the minimum scale
		void SetMinScale(double Scale);

		//! Set the increment for the scale during the detection process
		void SetScaleStep(double Step);

		//! Filter the regions using neighborhood criteria
		void FilterRegions(CRectVector *Regions,int NumNeighbors=3);

		//! Merge similar regions into only one region
		void GroupRegions(CRectVector *Regions,REGJOIN_METHOD Method=REGJOIN_MEAN);
#endif
		
	protected:
							
		//! Attributes
	protected:		

		//! Classifier used on the detection step
		CClassifier *m_Classifier;

		//! Minimum scale to detect (relative to window size)
		double m_MinScale;

		//! Maximum scale to detect (relative to window size)
		double m_MaxScale;

		//! Increment step for the scale value
		double m_ScaleStep;
	};	
}

#endif // __DETECTOR_H__
